CREATE TABLE [dbo].[TMDOCU_PROV]
(
[CO_EMPR] [dbo].[TD_VC_002] NOT NULL,
[CO_PROV] [dbo].[TD_VC_020] NOT NULL,
[CO_TIPO_DOCU] [dbo].[TD_VC_003] NOT NULL,
[NU_DOCU_PROV] [dbo].[TD_VC_020] NOT NULL,
[ST_ORIG_COSE] [dbo].[TD_VC_001] NULL,
[FE_EMIS] [dbo].[TD_DT_001] NOT NULL,
[CO_TIPO_OPER] [dbo].[TD_VC_003] NULL,
[CO_COND_PAGO] [dbo].[TD_VC_003] NOT NULL,
[CO_UNID_CONC] [dbo].[TD_VC_003] NOT NULL,
[FE_VENC] [dbo].[TD_DT_001] NOT NULL,
[FA_TIPO_CAMB] [dbo].[TD_NU_015_006] NOT NULL CONSTRAINT [DF__TMDOCU_PR__FA_TI__2744C181] DEFAULT ((1.000)),
[CO_MONE] [dbo].[TD_VC_003] NOT NULL,
[IM_BRUT_AFEC] [dbo].[TD_NU_016_004] NOT NULL CONSTRAINT [DF__TMDOCU_PR__IM_BR__2838E5BA] DEFAULT ((0)),
[FE_RECE] [dbo].[TD_DT_001] NULL,
[FE_PROG_PAGO] [dbo].[TD_DT_001] NULL,
[FA_CAMB_EXTR] [dbo].[TD_NU_015_006] NULL,
[IM_BRUT_INAF] [dbo].[TD_NU_016_004] NOT NULL CONSTRAINT [DF__TMDOCU_PR__IM_BR__292D09F3] DEFAULT ((0)),
[FE_REGI_COMP] [dbo].[TD_DT_001] NULL,
[IM_GAFI] [dbo].[TD_NU_016_004] NOT NULL CONSTRAINT [DF__TMDOCU_PR__IM_GA__2A212E2C] DEFAULT ((0)),
[IM_MORA] [dbo].[TD_NU_016_004] NOT NULL CONSTRAINT [DF__TMDOCU_PR__IM_MO__2B155265] DEFAULT ((0)),
[IM_FLET] [dbo].[TD_NU_016_004] NOT NULL CONSTRAINT [DF__TMDOCU_PR__IM_FL__2C09769E] DEFAULT ((0)),
[ST_AFEC_GAFI] [dbo].[TD_VC_001_SINO] NULL CONSTRAINT [DF__TMDOCU_PR__ST_AF__2CFD9AD7] DEFAULT ('N'),
[ST_AFEC_MORA] [dbo].[TD_VC_001_SINO] NULL CONSTRAINT [DF__TMDOCU_PR__ST_AF__2EE5E349] DEFAULT ('N'),
[ST_AFEC_FLET] [dbo].[TD_VC_001_SINO] NULL CONSTRAINT [DF__TMDOCU_PR__ST_AF__30CE2BBB] DEFAULT ('N'),
[ST_DCT1_BRAF] [dbo].[TD_VC_001_SINO] NULL CONSTRAINT [DF__TMDOCU_PR__ST_DC__32B6742D] DEFAULT ('N'),
[ST_DCT1_BRIN] [dbo].[TD_VC_001_SINO] NULL CONSTRAINT [DF__TMDOCU_PR__ST_DC__349EBC9F] DEFAULT ('N'),
[ST_DCT1_GAFI] [dbo].[TD_VC_001_SINO] NULL CONSTRAINT [DF__TMDOCU_PR__ST_DC__36870511] DEFAULT ('N'),
[ST_DCT1_MORA] [dbo].[TD_VC_001_SINO] NULL CONSTRAINT [DF__TMDOCU_PR__ST_DC__386F4D83] DEFAULT ('N'),
[ST_DCT1_FLET] [dbo].[TD_VC_001_SINO] NULL CONSTRAINT [DF__TMDOCU_PR__ST_DC__3A5795F5] DEFAULT ('N'),
[ST_DCT2_BRAF] [dbo].[TD_VC_001_SINO] NULL CONSTRAINT [DF__TMDOCU_PR__ST_DC__3C3FDE67] DEFAULT ('N'),
[ST_DCT2_BRIN] [dbo].[TD_VC_001_SINO] NULL CONSTRAINT [DF__TMDOCU_PR__ST_DC__3E2826D9] DEFAULT ('N'),
[ST_DCT2_GAFI] [dbo].[TD_VC_001_SINO] NULL CONSTRAINT [DF__TMDOCU_PR__ST_DC__40106F4B] DEFAULT ('N'),
[ST_DCT2_MORA] [dbo].[TD_VC_001_SINO] NULL CONSTRAINT [DF__TMDOCU_PR__ST_DC__41F8B7BD] DEFAULT ('N'),
[ST_DCT2_FLET] [dbo].[TD_VC_001_SINO] NULL CONSTRAINT [DF__TMDOCU_PR__ST_DC__43E1002F] DEFAULT ('N'),
[PC_DCT1] [dbo].[TD_NU_009_004] NOT NULL CONSTRAINT [DF__TMDOCU_PR__PC_DC__45C948A1] DEFAULT ((0)),
[IM_DCT1] [dbo].[TD_NU_016_004] NOT NULL CONSTRAINT [DF__TMDOCU_PR__IM_DC__46BD6CDA] DEFAULT ((0)),
[PC_DCT2] [dbo].[TD_NU_009_004] NOT NULL CONSTRAINT [DF__TMDOCU_PR__PC_DC__47B19113] DEFAULT ((0)),
[IM_DCT2] [dbo].[TD_NU_016_004] NOT NULL CONSTRAINT [DF__TMDOCU_PR__IM_DC__48A5B54C] DEFAULT ((0)),
[PC_IMP1] [dbo].[TD_NU_009_004] NOT NULL CONSTRAINT [DF__TMDOCU_PR__PC_IM__4999D985] DEFAULT ((0)),
[IM_IMP1] [dbo].[TD_NU_016_004] NOT NULL CONSTRAINT [DF__TMDOCU_PR__IM_IM__4A8DFDBE] DEFAULT ((0)),
[PC_IMP2] [dbo].[TD_NU_009_004] NOT NULL CONSTRAINT [DF__TMDOCU_PR__PC_IM__4B8221F7] DEFAULT ((0)),
[CO_IMP1] [dbo].[TD_VC_003] NULL,
[IM_IMP2] [dbo].[TD_NU_016_004] NOT NULL CONSTRAINT [DF__TMDOCU_PR__IM_IM__4C764630] DEFAULT ((0)),
[PC_IMP3] [dbo].[TD_NU_009_004] NOT NULL CONSTRAINT [DF__TMDOCU_PR__PC_IM__4D6A6A69] DEFAULT ((0)),
[CO_IMP2] [dbo].[TD_VC_003] NULL,
[IM_IMP3] [dbo].[TD_NU_016_004] NOT NULL CONSTRAINT [DF__TMDOCU_PR__IM_IM__4E5E8EA2] DEFAULT ((0)),
[IM_TOTA] [dbo].[TD_NU_016_004] NOT NULL CONSTRAINT [DF__TMDOCU_PR__IM_TO__4F52B2DB] DEFAULT ((0)),
[IM_PAGA] [dbo].[TD_NU_016_004] NOT NULL CONSTRAINT [DF__TMDOCU_PR__IM_PA__5046D714] DEFAULT ((0)),
[CO_IMP3] [dbo].[TD_VC_003] NULL,
[TI_DOCU_ORIG] [dbo].[TD_VC_003] NULL,
[NU_DOCU_ORIG] [dbo].[TD_VC_020] NULL,
[FE_DOCU_ORIG] [dbo].[TD_DT_001] NULL,
[ST_CONT] [dbo].[TD_VC_001_INTE] NOT NULL CONSTRAINT [DF__TMDOCU_PR__ST_CO__513AFB4D] DEFAULT ('N'),
[DE_OBSE] [dbo].[TD_VC_100] NULL,
[CO_ESTA_DOCU] [dbo].[TD_VC_003] NOT NULL,
[FE_REND_GAST] [dbo].[TD_DT_001] NULL,
[NU_COMP_SERV] [dbo].[TD_VC_020] NULL,
[NU_CORR_COMP] [dbo].[TD_VC_020] NULL,
[PC_SCRF] [dbo].[TD_NU_009_004] NULL CONSTRAINT [DF__TMDOCU_PR__PC_SC__532343BF] DEFAULT ((0)),
[NU_REND_GAST] [dbo].[TD_VC_010] NULL,
[IM_SCRF] [dbo].[TD_NU_016_004] NULL CONSTRAINT [DF__TMDOCU_PR__IM_SC__541767F8] DEFAULT ((0)),
[IM_SCF1] [dbo].[TD_NU_016_004] NULL CONSTRAINT [DF__TMDOCU_PR__IM_SC__550B8C31] DEFAULT ((0)),
[NU_CANJ] [dbo].[TD_VC_008] NULL,
[IM_SCF2] [dbo].[TD_NU_016_004] NULL CONSTRAINT [DF__TMDOCU_PR__IM_SC__55FFB06A] DEFAULT ((0)),
[IM_SCF3] [dbo].[TD_NU_016_004] NULL CONSTRAINT [DF__TMDOCU_PR__IM_SC__56F3D4A3] DEFAULT ((0)),
[NU_RENO] [dbo].[TD_VC_008] NULL,
[NU_PROC] [dbo].[TD_IN_001] NULL CONSTRAINT [DF__TMDOCU_PR__NU_PR__57E7F8DC] DEFAULT ((0)),
[CO_MODE_DIST] [dbo].[TD_VC_003] NULL,
[ST_REND_COMP] [dbo].[TD_VC_001] NULL,
[NU_SREN_GAST] [dbo].[TD_VC_050] NULL,
[NU_IMPO] [dbo].[TD_VC_020] NULL,
[NU_EXPO] [dbo].[TD_VC_020] NULL,
[NU_ASTO] [dbo].[TD_VC_010] NULL,
[CO_ACTI_DETR] [dbo].[TD_VC_003] NULL,
[CO_TIOP_DETR] [dbo].[TD_VC_003] NULL,
[ST_SUJE_DETR] [dbo].[TD_VC_001] NULL,
[TI_PROV] [dbo].[TD_VC_003] NULL,
[NU_CORR_PROV] [dbo].[TD_VC_020] NULL,
[NU_DEPO_DETR] [dbo].[TD_VC_020] NULL,
[FE_DEPO_DETR] [dbo].[TD_DT_001] NULL,
[CO_CALI] [dbo].[TD_VC_003] NULL,
[CO_BANC] [dbo].[TD_VC_003] NULL,
[CO_TIPO_FINA] [dbo].[TD_VC_003] NULL,
[FE_PAGO_AGEN] [dbo].[TD_DT_001] NULL,
[NU_ORDE_FORM] [dbo].[TD_NU_016_004] NULL CONSTRAINT [DF__TMDOCU_PR__NU_OR__58DC1D15] DEFAULT ((0)),
[CO_DEST] [dbo].[TD_VC_003] NULL,
[NU_DEST] [dbo].[TD_VC_003] NULL,
[ST_AFEC_IISC] [dbo].[TD_VC_001_SINO] NULL CONSTRAINT [DF__TMDOCU_PR__ST_AF__59D0414E] DEFAULT ('N'),
[ST_AFEC_DETR] [dbo].[TD_VC_001_SINO] NULL CONSTRAINT [DF__TMDOCU_PR__ST_AF__5BB889C0] DEFAULT ('N'),
[PO_DETR] [dbo].[TD_NU_009_004] NULL CONSTRAINT [DF__TMDOCU_PR__PO_DE__5CACADF9] DEFAULT ((0)),
[ST_AFEC_RETE] [dbo].[TD_VC_001_SINO] NULL CONSTRAINT [DF__TMDOCU_PR__ST_AF__5DA0D232] DEFAULT ('N'),
[CO_PROV_EXTR] [dbo].[TD_VC_050] NULL,
[ST_FORM_1062] [dbo].[TD_VC_001_SINO] NULL CONSTRAINT [DF__TMDOCU_PR__ST_FO__5F891AA4] DEFAULT ('N'),
[ST_FORM_1262] [dbo].[TD_VC_001_SINO] NULL CONSTRAINT [DF__TMDOCU_PR__ST_FO__61716316] DEFAULT ('N'),
[ST_FORM_1662] [dbo].[TD_VC_001_SINO] NULL CONSTRAINT [DF__TMDOCU_PR__ST_FO__6359AB88] DEFAULT ('N'),
[CO_ADUA] [dbo].[TD_VC_003] NULL,
[NU_ANIO_POLI] [dbo].[TD_VC_004] NULL,
[CO_CCOS_IGVD] [dbo].[TD_VC_020] NULL,
[CO_SUBR] [dbo].[TD_VC_003] NULL,
[CO_CNTA_PROV] [dbo].[TD_VC_020] NULL,
[ST_GRAV_NGRA] [dbo].[TD_VC_003] NULL,
[IM_VALO_REFE] [dbo].[TD_NU_016_004] NULL CONSTRAINT [DF__TMDOCU_PR__IM_VA__6541F3FA] DEFAULT ((0)),
[ST_FLET] [dbo].[TD_VC_001_SINO] NOT NULL CONSTRAINT [DF__TMDOCU_PR__ST_FL__66361833] DEFAULT ('N'),
[CO_DEPE_ADUA] [dbo].[TD_VC_003] NULL,
[NU_ANNO_ADUA] [dbo].[TD_VC_004] NULL,
[FE_PROG] [dbo].[TD_DT_001] NULL,
[TI_GAST] [dbo].[TD_VC_006] NULL,
[IM_VARE] [dbo].[TD_NU_016_004] NOT NULL CONSTRAINT [DF__TMDOCU_PR__IM_VA__681E60A5] DEFAULT ((0)),
[ST_IGVP] [dbo].[TD_VC_001_SINO] NOT NULL CONSTRAINT [DF__TMDOCU_PR__ST_IG__691284DE] DEFAULT ('N'),
[CO_PROV_NCRB] [dbo].[TD_VC_050] NULL,
[CO_TIPO_NCRB] [dbo].[TD_VC_050] NULL,
[NU_DOCU_NCRB] [dbo].[TD_VC_020] NULL,
[NU_PROC_CARG] [dbo].[TD_IN_001] NULL CONSTRAINT [DF__TMDOCU_PR__NU_PR__6AFACD50] DEFAULT ((0)),
[CO_USUA_CREA] [dbo].[TD_VC_008_USUA] NOT NULL CONSTRAINT [DF__TMDOCU_PR__CO_US__6BEEF189] DEFAULT (suser_sname()),
[FE_USUA_CREA] [dbo].[TD_DT_001_SIST] NOT NULL CONSTRAINT [DF__TMDOCU_PR__FE_US__6CE315C2] DEFAULT (getdate()),
[CO_USUA_MODI] [dbo].[TD_VC_008_USUA] NOT NULL CONSTRAINT [DF__TMDOCU_PR__CO_US__6DD739FB] DEFAULT (suser_sname()),
[FE_USUA_MODI] [dbo].[TD_DT_001_SIST] NOT NULL CONSTRAINT [DF__TMDOCU_PR__FE_US__6ECB5E34] DEFAULT (getdate()),
[CO_BANC_PRES] [dbo].[TD_VC_003] NULL,
[CO_UNID_PRES] [dbo].[TD_VC_003] NULL,
[NU_CNTA_PRES] [dbo].[TD_VC_020] NULL,
[AA_BNCO_PRES] [dbo].[TD_VC_004] NULL,
[MM_BNCO_PRES] [dbo].[TD_VC_002] NULL,
[TI_MOVI_PRES] [dbo].[TD_VC_001] NULL,
[NU_COMP_PRES] [dbo].[TD_VC_008] NULL
) ON [PRIMARY]
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE   Trigger [dbo].[tD_TMDOCU_PROV_D01] on [dbo].[TMDOCU_PROV] for DELETE
/*---------------------------------------------------------*/
/*---- Empresa              : OFISIS S.A.              ----*/
/*---- Cliente              : OFISIS S.A.              ----*/
/*---- Sistema              : OFITESO                  ----*/
/*---- M½dulo               : Inventarios              ----*/
/*---- Programa             : Trigger                  ----*/
/*---- Script               : TRIGGERS_TMDOCU_PROV.SQL ----*/
/*---- Nombre TR            : tD_TMDOCU_PROV_D01       ----*/
/*---- Desarrollado por     : Carlos Marquez Escobar   ----*/
/*---- Fecha Creaci½n       : 24/03/2004              ----*/
/*---- Base de Datos        : SQL	                   ----*/
/*---- Versi½n              : 8.1                      ----*/
/*---- Invoca a SP          :                          ----*/
/*---------------------------------------------------------*/
/*---- Modificado 1 por     : Carlos Marquez Escobar   ----*/
/*---- Fecha Modificaci½n   : 24/01/2006               ----*/
/*---- Detalle Modificacicn : Auditar eliminacion      ----*/
/*---------------------------------------------------------*/
/*---- Comentarios: actualiza la Bitacora Docs Elimina ----*/
/*----                                                 ----*/
/*----                                                 ----*/
/*---------------------------------------------------------*/
/*---- Drop TRIGGER tD_TMDOCU_PROV_D01                 ----*/
/*---- Grant All On tD_TMDOCU_PROV_D01 to PUBLIC       ----*/
/*---------------------------------------------------------*/
As
Begin 
  Declare 
  @CSCO_EMPR	    TD_VC_002,
  @CSCO_CLAV_TAOR	TD_VC_100,
  @CSCO_PROV        TD_VC_020, 
  @CSCO_TIPO_DOCU   TD_VC_003, 
  @CSNU_DOCU_PROV   TD_VC_020,

  @CSCO_USUA_MODI	TD_VC_008_USUA,
  @CSCO_USUA_CREA	TD_VC_008_USUA,
  @CDFE_USUA_MODI	TD_DT_001_SIST,
  @CDFE_USUA_CREA	TD_DT_001_SIST


  Declare  CT_TMDOCU_PROV_D01_1 Cursor 
  For 
  Select   CO_EMPR, 
		Replicate (' ', 20 - Len(RTrim(Ltrim(IsNull(CO_PROV,''))))) + RTrim(Ltrim(IsNull(CO_PROV,''))) + 
		Replicate (' ', 03 - Len(RTrim(Ltrim(IsNull(CO_TIPO_DOCU,''))))) + RTrim(Ltrim(IsNull(CO_TIPO_DOCU,''))) +
		Replicate (' ', 20 - Len(RTrim(Ltrim(IsNull(NU_DOCU_PROV,''))))) + RTrim(Ltrim(IsNull(NU_DOCU_PROV,''))) +
		Replicate (' ', 10 - Len(RTrim(Ltrim(IsNull(NU_ASTO,''))))) + RTrim(Ltrim(IsNull(NU_ASTO,''))) +
		Replicate (' ', 03 - Len(RTrim(Ltrim(IsNull(CO_ESTA_DOCU,''))))) + RTrim(Ltrim(IsNull(CO_ESTA_DOCU,''))) +
		Replicate (' ', 20 - Len(RTrim(Ltrim(IsNull(NU_CORR_COMP,''))))) + RTrim(Ltrim(IsNull(NU_CORR_COMP,''))), CO_PROV, CO_TIPO_DOCU, NU_DOCU_PROV,
		CO_USUA_MODI, FE_USUA_MODI

  From     Deleted

  Open    CT_TMDOCU_PROV_D01_1
  Fetch   CT_TMDOCU_PROV_D01_1 Into
          @CSCO_EMPR, @CSCO_CLAV_TAOR, @CSCO_PROV, @CSCO_TIPO_DOCU, @CSNU_DOCU_PROV,
		@CSCO_USUA_MODI, @CDFE_USUA_MODI
  While @@Fetch_Status = 0
  Begin
    If @@Fetch_Status < 0
      Begin
        Close CT_TMDOCU_PROV_D01_1
        Deallocate tD_TMDOCU_PROV_D01_1
      End
	
		Insert Into TMREGI_ELIM 
		(CO_EMPR, CO_TABL_ORIG, DE_TABL_ORIG, CO_CLAV_TAOR, CO_USUA_CREA, FE_USUA_CREA, CO_USUA_MODI, FE_USUA_MODI)
		Values 
		(@CSCO_EMPR, 3, 'MAESTRO PROVEEDORES', @CSCO_CLAV_TAOR,
			  @CSCO_USUA_MODI, @CDFE_USUA_MODI, @CSCO_USUA_MODI, @CDFE_USUA_MODI)

	  Fetch   CT_TMDOCU_PROV_D01_1 Into
	          @CSCO_EMPR, @CSCO_CLAV_TAOR, @CSCO_PROV, @CSCO_TIPO_DOCU, @CSNU_DOCU_PROV,
			  @CSCO_USUA_MODI, @CDFE_USUA_MODI
  End -- Del Cursor
  Close CT_TMDOCU_PROV_D01_1
  Deallocate CT_TMDOCU_PROV_D01_1
End
/*---------------------------Fin------------------------*/
  
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

CREATE TRIGGER [dbo].[TI_TMDOCU_PROV_I01] ON [dbo].[TMDOCU_PROV] FOR INSERT
/*---------------------------------------------------------*/
/*---- Empresa              : OFISIS S.A.              ----*/
/*---- Cliente              : OFISIS S.A.              ----*/
/*---- Sistema              : OFITESO                  ----*/
/*---- M½dulo               : Empresa                  ----*/
/*---- Programa             : Trigger                  ----*/
/*---- Script               : TRIGGERS_TMDOCU_PROV.SQL ----*/
/*---- Nombre TR            : TI_TMDOCU_PROV_I01       ----*/
/*---- Desarrollado por     : Gianmarco Lindo Huertas  ----*/
/*---- Fecha Creaci½n       : 15/06/2001               ----*/
/*---- Base de Datos        : SQL_Server               ----*/
/*---- Versi½n              : 7.0                      ----*/
/*---- Invoca a SP          :                          ----*/
/*---------------------------------------------------------*/
/*---- Modificado 1 por     :  DANIEL CHIANG           ----*/
/*---- Fecha Modificaci½n   :  21/01/2005              ----*/
/*---- Detalle Modificacicn :  SE CORRIGIO LA PARTE DE COMP.----*/
/*---- 			       RETENCION Y CONSTANCIAS ----*/
/*---------------------------------------------------------*/
/*---- Comentarios: Genera Numero Correlativo, para    ----*/
/*----              la secuencia de ingreso de Compra  ----*/
/*----                                                 ----*/
/*---------------------------------------------------------*/
/*---- Drop TRIGGER tI_TMDOCU_PROV_I01                 ----*/
/*---- Grant All On tI_TMDOCU_PROV_I01 to PUBLIC       ----*/
/*---------------------------------------------------------*/
NOT FOR REPLICATION  
As
Begin
  Declare
  @VSNU_CORR_COMP  TD_VC_020,
  @VSST_REGI_COMP  TD_VC_020,
  @VNNU_CORR_COMP  Int,
  @CSCO_EMPR       TD_VC_002,
  @CSCO_PROV       TD_VC_020,
  @CSCO_TIPO_DOCU  TD_VC_003,
  @CSNU_DOCU_PROV  TD_VC_020,
  @CDFE_REGI_COMP  TD_DT_001,
  @CDFE_PROG_PAGO TD_DT_001,
  @CDCO_MONE  TD_VC_003,
  @CNIM_TOTA  TD_NU_016_004,
  @CNIM_SALD  TD_NU_016_004,
  @CSNU_REND_GAST  TD_VC_010,
  @VSTI_DOCU_RETE  TD_VC_003, 
  @VSTI_DOCU_CORE  TD_VC_003

  Declare CT_TMDOCU_PROV_I01 Cursor
  For
  Select	CO_EMPR, CO_PROV, CO_TIPO_DOCU, NU_DOCU_PROV,
			FE_REGI_COMP, FE_PROG_PAGO, CO_MONE, IM_TOTA, IM_TOTA - IM_PAGA,
			NU_REND_GAST
    From Inserted
  
  Open  CT_TMDOCU_PROV_I01
  Fetch CT_TMDOCU_PROV_I01 Into
		@CSCO_EMPR, @CSCO_PROV, @CSCO_TIPO_DOCU, 
		@CSNU_DOCU_PROV, @CDFE_REGI_COMP, @CDFE_PROG_PAGO, @CDCO_MONE, @CNIM_TOTA, @CNIM_SALD,
		@CSNU_REND_GAST
  While @@Fetch_Status = 0
  Begin
		If @@Fetch_Status < 0
		Begin
			Close CT_TMDOCU_PROV_I01
			Deallocate CT_TMDOCU_PROV_I01
		End

		-- Verifica si Tipo de Documento aparece en registro de Compras --
		Select @VSST_REGI_COMP = Isnull( ST_REGI_COMP, 'N')
		From TTDOCU_CNTB
		Where TI_DOCU = @CSCO_TIPO_DOCU
		
		If @VSST_REGI_COMP = 'S'
		Begin
		
			Select @VNNU_CORR_COMP = Isnull( NU_CORR, 0 ) + 1
			From   TTCORR_DOPR
			Where  CO_EMPR = @CSCO_EMPR
			And NU_MESE = Month( @CDFE_REGI_COMP )
			And NU_ANNO = Year( @CDFE_REGI_COMP )
			
			If @VNNU_CORR_COMP Is NUll
			Select @VNNU_CORR_COMP = 1
			
			
			

		If OBJECTPROPERTY ( OBJECT_ID( 'TI_TMDOCU_PRRE_I01' ), 'ExecIsTriggerDisabled' ) =  1 -- Trigger Deshabilitado
			Or 
		   Not  Exists( Select CO_EMPR
				From   TMDOCU_PRRE
				Where  CO_EMPR = @CSCO_EMPR
				And CO_PROV = @CSCO_PROV
				And CO_TIPO_DOCU = @CSCO_TIPO_DOCU
				And NU_DOCU_PROV = @CSNU_DOCU_PROV )
			
			BEGIN --- 0001
			
				If Not Exists (Select CO_EMPR    
				From 	 TTCORR_DOPR       
				Where  CO_EMPR = @CSCO_EMPR
				And NU_MESE = Month( @CDFE_REGI_COMP )
				And NU_ANNO = Year( @CDFE_REGI_COMP ) )
				
					Insert Into TTCORR_DOPR(CO_EMPR, NU_MESE, NU_ANNO, NU_CORR )
					Values (@CSCO_EMPR, Month( @CDFE_REGI_COMP ), Year( @CDFE_REGI_COMP ), @VNNU_CORR_COMP )
				
				
				Else
					Update TTCORR_DOPR					Set    NU_CORR = @VNNU_CORR_COMP 
					Where  CO_EMPR = @CSCO_EMPR
					And NU_MESE = Month( @CDFE_REGI_COMP )
					And NU_ANNO = Year( @CDFE_REGI_COMP )
				
				Select @VNNU_CORR_COMP = @VNNU_CORR_COMP + 1000000
				Select @VSNU_CORR_COMP = SubString( Convert(Varchar(07), @VNNU_CORR_COMP), 2, 6)
				Select @VSNU_CORR_COMP = SubString( Convert(Varchar(03), (Month( @CDFE_REGI_COMP ) + 100)), 2, 2) + @VSNU_CORR_COMP
				Select @VSNU_CORR_COMP = SubString( Convert(Varchar(04), (Year( @CDFE_REGI_COMP ) ) ), 3, 2) + @VSNU_CORR_COMP
				
				Update TMDOCU_PROV
				Set    NU_CORR_COMP = @VSNU_CORR_COMP
				Where  CO_EMPR = @CSCO_EMPR
				And CO_PROV = @CSCO_PROV
				And CO_TIPO_DOCU = @CSCO_TIPO_DOCU
				And NU_DOCU_PROV = @CSNU_DOCU_PROV
				
			END -- 0001
		
		End
		
		Select   @VSTI_DOCU_RETE = TI_DOCU From TTDOCU_CNTB
		Where ST_DOCU_0021 = 'S'

		Select   @VSTI_DOCU_CORE  = TI_DOCU From TTDOCU_CNTB
		Where ST_DOCU_0022 = 'S'
		
		If ( @CSCO_TIPO_DOCU != @VSTI_DOCU_RETE And @CSCO_TIPO_DOCU != @VSTI_DOCU_CORE )  And Len(Ltrim(Rtrim(IsNull(@CSNU_REND_GAST,'')))) = 0 
			Insert Into TDPROG_PAGO ( CO_EMPR, CO_PROV, CO_TIPO_DOCU, NU_DOCU_PROV, NU_SECU,
			FE_PROG, CO_MONE, IM_PROG, IM_SALD, TI_SITU, ST_DOCU_CIER)
			Values ( @CSCO_EMPR, @CSCO_PROV, @CSCO_TIPO_DOCU, @CSNU_DOCU_PROV, 1,
			@CDFE_PROG_PAGO, @CDCO_MONE, @CNIM_TOTA, @CNIM_SALD,  'ACT', 'S' ) 

      Fetch CT_TMDOCU_PROV_I01 Into
            @CSCO_EMPR, @CSCO_PROV, @CSCO_TIPO_DOCU, @CSNU_DOCU_PROV,
            @CDFE_REGI_COMP, @CDFE_PROG_PAGO, @CDCO_MONE, @CNIM_TOTA, @CNIM_SALD,
			@CSNU_REND_GAST
  End
  Close CT_TMDOCU_PROV_I01
  Deallocate CT_TMDOCU_PROV_I01
End
/*-------------------------------------- Fin de Trigger --------------------------------------*/

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

CREATE Trigger [dbo].[TU_TMDOCU_PROV_U01] On [dbo].[TMDOCU_PROV]
For Update
/*---------------------------------------------------------*/
/*---- Empresa              : OFISIS S.A.              ----*/
/*---- Cliente              : OFISIS S.A.              ----*/
/*---- Sistema              : OFITESO                  ----*/
/*---- M½dulo               : Empresa                  ----*/
/*---- Programa             : Trigger                  ----*/
/*---- Script               : TRIGGERS_TMDOCU_PROV.SQL ----*/
/*---- Nombre TR            : TU_TMDOCU_PROV_I01       ----*/
/*---- Desarrollado por     : Reynaldo Menacho         ----*/
/*---- Fecha Creaci½n       : 30/03/2004               ----*/
/*---- Base de Datos        : SQL_Server               ----*/
/*---- Versi½n              : 20000                    ----*/
/*---- Invoca a SP          :                          ----*/
/*---------------------------------------------------------*/
/*---- Modificado 1 por     :                          ----*/
/*---- Fecha Modificaci½n   :                          ----*/    
/*---- Detalle Modificacicn :                          ----*/  
/*---------------------------------------------------------*/
/*---- Comentarios: Asigna nuevo n-mero de correlativo y asiento      ----*/
/*---- cuando se cambia la fecha de registro de compras a otro periodo----*/
/*---------------------------------------------------------*/
/*---------------------------------------------------------*/
/*---- Drop TRIGGER TU_TMDOCU_PROV_U01                 ----*/
/*---- Grant All On TU_TMDOCU_PROV_I01 to PUBLIC       ----*/
/*---------------------------------------------------------*/
As
If Update(CO_UNID_CONC) OR Update(FE_REGI_COMP)
Begin
  Declare 
  @CSCO_EMPR       TD_VC_002,
  @CSCO_PROV       TD_VC_020,
  @CSCO_TIPO_DOCU  TD_VC_003,
  @CSNU_DOCU_PROV  TD_VC_020,
  @CDFE_REGI_COMP  TD_DT_001,
  @CSNU_ASTO	   TD_VC_010,
  @CSCO_UNID_CONC  TD_VC_003,
  @CSCO_TIPO_OPER  TD_VC_003,
  @VSNU_ASTO       TD_VC_008,
  @VDFE_REGI_COMP  TD_DT_001,
  @VSST_REGI_COMP  TD_VC_001,
  @VNNU_CORR_COMP  TD_IN_001,
  @VSNU_CORR_COMP  TD_VC_020,
  @VSST_FLAG       TD_VC_001,
  @VSCO_UNID_CONC  TD_VC_003,
  @CSCO_USUA_MODI  TD_VC_008, 
  @CDFE_USUA_MODI  TD_DT_001,
  @VSCO_TIPO_OPER  TD_VC_003
  SELECT  @VSST_FLAG = '0'

  Declare CT_TMDOCU_PROV_U01_1 Cursor
  For
  Select CO_EMPR, CO_PROV, CO_TIPO_DOCU, NU_DOCU_PROV, CO_UNID_CONC, CO_TIPO_OPER, FE_REGI_COMP, NU_ASTO,
         CO_USUA_MODI, FE_USUA_MODI
  From   inserted

  Open  CT_TMDOCU_PROV_U01_1
  Fetch CT_TMDOCU_PROV_U01_1 
  Into @CSCO_EMPR, @CSCO_PROV, @CSCO_TIPO_DOCU, @CSNU_DOCU_PROV, @CSCO_UNID_CONC, 
  @CSCO_TIPO_OPER, @CDFE_REGI_COMP, @CSNU_ASTO, @CSCO_USUA_MODI, @CDFE_USUA_MODI

  While @@Fetch_Status = 0
  Begin
    If  @@Fetch_Status < 0
      Begin
        Close CT_TMDOCU_PROV_U01_1
        Deallocate CT_TMDOCU_PROV_U01_1
      End

            Select @VDFE_REGI_COMP = FE_REGI_COMP, @VSCO_UNID_CONC = CO_UNID_CONC,
                   @VSCO_TIPO_OPER = CO_TIPO_OPER
            From   DELETED 
            Where  CO_EMPR = @CSCO_EMPR
            And    CO_PROV = @CSCO_PROV
            And    CO_TIPO_DOCU = @CSCO_TIPO_DOCU
            And    NU_DOCU_PROV = @CSNU_DOCU_PROV          	 
            
            If (Year(@VDFE_REGI_COMP) != Year(@CDFE_REGI_COMP) Or Month(@VDFE_REGI_COMP) != Month(@CDFE_REGI_COMP))
               AND (@VSCO_TIPO_OPER IS NOT NULL Or ltrim(rtrim(@VSCO_TIPO_OPER)) != ''   ) 
               Begin 

                Select @VSST_FLAG = '1' 
		      --Se anula el voucher en contabilidad
          	 Update TXMVTO_CNTB
          	 Set    SI_MVTO_CNTB = 'ELI', CO_USUA_MODI = @CSCO_USUA_MODI, FE_USUA_MODI = @CDFE_USUA_MODI
                Where  CO_EMPR = @CSCO_EMPR          	 And    NU_CNTB_EMPR = 1
          	 And    CO_UNID_CNTB = @VSCO_UNID_CONC
                And    CO_OPRC_CNTB = Left(@CSNU_ASTO, 3)
                And    NU_ANNO = Year(@VDFE_REGI_COMP)
                And    NU_MESE = Month(@VDFE_REGI_COMP)
                And    NU_ASTO = '00000' + Right(@CSNU_ASTO, 5)          	 
                
		      --Se genera el nuevo NU_ASTO
		      Exec SP_TTULTI_ASTO_Q01 @CSCO_EMPR, @CSCO_UNID_CONC, @CSCO_TIPO_OPER, @CDFE_REGI_COMP, @VSNU_ASTO OUTPUT

   		      --Se genera el nuevo NU_CORR_COMP
	           -- Verifica si Tipo de Documento aparece en registro de Compras --
	           Select @VSST_REGI_COMP = Isnull( ST_REGI_COMP, 'N')
	           From TTDOCU_CNTB
	           Where TI_DOCU = @CSCO_TIPO_DOCU

		 If @VSST_REGI_COMP = 'S'
	         Begin

                 Select @VNNU_CORR_COMP = Isnull( NU_CORR, 0 ) + 1
                 From   TTCORR_DOPR
                 Where  CO_EMPR = @CSCO_EMPR
              	  And NU_MESE = Month( @CDFE_REGI_COMP )
          	  And NU_ANNO = Year( @CDFE_REGI_COMP )
 
                 If @VNNU_CORR_COMP Is NUll
                   Select @VNNU_CORR_COMP = 1

                 If Not Exists (Select CO_EMPR    
                                From 	 TTCORR_DOPR       
                                Where  CO_EMPR = @CSCO_EMPR
                                And NU_MESE = Month( @CDFE_REGI_COMP )
                  	            And NU_ANNO = Year( @CDFE_REGI_COMP ) )

                   Insert Into TTCORR_DOPR(CO_EMPR, NU_MESE, NU_ANNO, NU_CORR )
            	    Values (@CSCO_EMPR, Month( @CDFE_REGI_COMP ), Year( @CDFE_REGI_COMP ), @VNNU_CORR_COMP )
                 Else
                   Update TTCORR_DOPR
                   Set    NU_CORR = @VNNU_CORR_COMP 
                   Where  CO_EMPR = @CSCO_EMPR
              	    And NU_MESE = Month( @CDFE_REGI_COMP )
              	    And NU_ANNO = Year( @CDFE_REGI_COMP )

	            Select @VNNU_CORR_COMP = @VNNU_CORR_COMP + 1000000
          	  Select @VSNU_CORR_COMP = SubString( Convert(Varchar(07), @VNNU_CORR_COMP), 2, 6)
	            Select @VSNU_CORR_COMP = SubString( Convert(Varchar(03), (Month( @CDFE_REGI_COMP ) + 100)), 2, 2) + @VSNU_CORR_COMP
          	  Select @VSNU_CORR_COMP = SubString( Convert(Varchar(04), (Year( @CDFE_REGI_COMP ) ) ), 3, 2) + @VSNU_CORR_COMP
	         End
		 Else
		   Select @VSNU_CORR_COMP = NULL


	        Update TMDOCU_PROV
             Set    NU_CORR_COMP = @VSNU_CORR_COMP,
		          NU_ASTO = @VSNU_ASTO,
		          ST_CONT = 'N', CO_USUA_MODI = @CSCO_USUA_MODI, FE_USUA_MODI = @CDFE_USUA_MODI
	        Where  CO_EMPR = @CSCO_EMPR
          	And  CO_PROV = @CSCO_PROV
          	And  CO_TIPO_DOCU = @CSCO_TIPO_DOCU
          	And  NU_DOCU_PROV = @CSNU_DOCU_PROV          	  
         End

       If @VSST_FLAG = '0' AND @VSCO_TIPO_OPER IS NOT NULL
          Begin 
            If @VSCO_UNID_CONC != @CSCO_UNID_CONC
               Begin 

	     --Se anula el voucher en contabilidad
             Update TXMVTO_CNTB
          	 Set    SI_MVTO_CNTB = 'ELI',CO_USUA_MODI = @CSCO_USUA_MODI, FE_USUA_MODI = @CDFE_USUA_MODI
          	 Where  CO_EMPR = @CSCO_EMPR
          	 And    NU_CNTB_EMPR = 1
          	 And    CO_UNID_CNTB = @VSCO_UNID_CONC
                 And    CO_OPRC_CNTB = Left(@CSNU_ASTO, 3)
                 And    NU_ANNO = Year(@CDFE_REGI_COMP)
                 And    NU_MESE = Month(@CDFE_REGI_COMP)
                 And    NU_ASTO = '00000' + Right(@CSNU_ASTO, 5)          	 
		 --Se genera el nuevo NU_ASTO
		 Exec SP_TTULTI_ASTO_Q01 @CSCO_EMPR, @CSCO_UNID_CONC, @CSCO_TIPO_OPER, @CDFE_REGI_COMP, @VSNU_ASTO OUTPUT

	         Update TMDOCU_PROV
                 Set    NU_ASTO = @VSNU_ASTO,
		        ST_CONT = 'N', CO_USUA_MODI = @CSCO_USUA_MODI, FE_USUA_MODI = @CDFE_USUA_MODI
	         Where  CO_EMPR = @CSCO_EMPR
          	 And    CO_PROV = @CSCO_PROV
          	 And    CO_TIPO_DOCU = @CSCO_TIPO_DOCU
          	 And    NU_DOCU_PROV = @CSNU_DOCU_PROV
            End
          End
----------------------------------------------------
            If (Year(@VDFE_REGI_COMP) != Year(@CDFE_REGI_COMP) Or Month(@VDFE_REGI_COMP) != Month(@CDFE_REGI_COMP))
               AND ( @VSCO_TIPO_OPER IS NULL Or ltrim(rtrim(@VSCO_TIPO_OPER)) = '')
               Begin 

                Select @VSST_FLAG = '1' 

   		      --Se genera el nuevo NU_CORR_COMP
	           -- Verifica si Tipo de Documento aparece en registro de Compras --
	           Select @VSST_REGI_COMP = Isnull( ST_REGI_COMP, 'N')
	           From TTDOCU_CNTB
	           Where TI_DOCU = @CSCO_TIPO_DOCU

   		   If @VSST_REGI_COMP = 'S'
	         Begin

                 Select @VNNU_CORR_COMP = Isnull( NU_CORR, 0 ) + 1
                 From   TTCORR_DOPR
                 Where  CO_EMPR = @CSCO_EMPR
              	  And NU_MESE = Month( @CDFE_REGI_COMP )
          	  And NU_ANNO = Year( @CDFE_REGI_COMP )
 
                 If @VNNU_CORR_COMP Is NUll
                   Select @VNNU_CORR_COMP = 1

                 If Not Exists (Select CO_EMPR    
                                From 	 TTCORR_DOPR       
                                Where  CO_EMPR = @CSCO_EMPR
                                And NU_MESE = Month( @CDFE_REGI_COMP )
                  	            And NU_ANNO = Year( @CDFE_REGI_COMP ) )

                   Insert Into TTCORR_DOPR(CO_EMPR, NU_MESE, NU_ANNO, NU_CORR )
            	    Values (@CSCO_EMPR, Month( @CDFE_REGI_COMP ), Year( @CDFE_REGI_COMP ), @VNNU_CORR_COMP )
                 Else
                   Update TTCORR_DOPR
                   Set    NU_CORR = @VNNU_CORR_COMP 
                   Where  CO_EMPR = @CSCO_EMPR
              	    And NU_MESE = Month( @CDFE_REGI_COMP )
              	    And NU_ANNO = Year( @CDFE_REGI_COMP )

	            Select @VNNU_CORR_COMP = @VNNU_CORR_COMP + 1000000
          	  Select @VSNU_CORR_COMP = SubString( Convert(Varchar(07), @VNNU_CORR_COMP), 2, 6)
	            Select @VSNU_CORR_COMP = SubString( Convert(Varchar(03), (Month( @CDFE_REGI_COMP ) + 100)), 2, 2) + @VSNU_CORR_COMP
          	  Select @VSNU_CORR_COMP = SubString( Convert(Varchar(04), (Year( @CDFE_REGI_COMP ) ) ), 3, 2) + @VSNU_CORR_COMP
	         End
		 Else
		   Select @VSNU_CORR_COMP = NULL


	        Update TMDOCU_PROV
             Set    NU_CORR_COMP = @VSNU_CORR_COMP,
		          ST_CONT = 'N', CO_USUA_MODI = @CSCO_USUA_MODI, FE_USUA_MODI = @CDFE_USUA_MODI
	        Where  CO_EMPR = @CSCO_EMPR
          	And  CO_PROV = @CSCO_PROV
          	And  CO_TIPO_DOCU = @CSCO_TIPO_DOCU
          	And  NU_DOCU_PROV = @CSNU_DOCU_PROV          	  
         End

     Fetch CT_TMDOCU_PROV_U01_1 
     Into  @CSCO_EMPR, @CSCO_PROV, @CSCO_TIPO_DOCU, @CSNU_DOCU_PROV, @CSCO_UNID_CONC, 
     @CSCO_TIPO_OPER, @CDFE_REGI_COMP, @CSNU_ASTO, @CSCO_USUA_MODI, @CDFE_USUA_MODI

  End
  Close CT_TMDOCU_PROV_U01_1
  Deallocate CT_TMDOCU_PROV_U01_1
End
/*------------------------ Fin ----------------------*/

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

CREATE Trigger [dbo].[TU_TMDOCU_PROV_U02] On [dbo].[TMDOCU_PROV]
For Update
/*---------------------------------------------------------*/
/*---- Empresa              : OFISIS S.A.              ----*/
/*---- Cliente              : OFISIS S.A.              ----*/
/*---- Sistema              : OFITESO                  ----*/
/*---- M½dulo               : Empresa                  ----*/
/*---- Programa             : Trigger                  ----*/
/*---- Script               : TRIGGERS_TMDOCU_PROV.SQL ----*/
/*---- Nombre TR            : TU_TMDOCU_PROV_I01       ----*/
/*---- Desarrollado por     : Reynaldo Menacho         ----*/
/*---- Fecha Creaci½n       : 30/03/2004               ----*/
/*---- Base de Datos        : SQL_Server               ----*/
/*---- Versi½n              : 20000                    ----*/
/*---- Invoca a SP          :                          ----*/
/*---------------------------------------------------------*/
/*---- Modificado 1 por     :                          ----*/
/*---- Fecha Modificaci½n   :                          ----*/    
/*---- Detalle Modificacicn :                          ----*/  
/*---------------------------------------------------------*/
/*---- Comentarios: Update tdprog_pago campo fecha programaci½n de pago  ----*/
/*---- siempre y cuando tenga un s½lo registro         ----*/
/*---------------------------------------------------------*/
/*---------------------------------------------------------*/
/*---- Drop TRIGGER TU_TMDOCU_PROV_U02                 ----*/
/*---- Grant All On TU_TMDOCU_PROV_U02 to PUBLIC       ----*/
/*---------------------------------------------------------*/
As
If Update(FE_PROG_PAGO)
Begin
  Declare 
  @CSCO_EMPR       TD_VC_002,
  @CSCO_PROV       TD_VC_020,
  @CSCO_TIPO_DOCU  TD_VC_003,
  @CSNU_DOCU_PROV  TD_VC_020,
  @VNNU_CONT_PAGO  TD_IN_001,
  @CDFE_PROG_PAGO  TD_DT_001,
  @CSCO_USUA_MODI  TD_VC_008, 
  @CDFE_USUA_MODI  TD_DT_001
/*
  @CDFE_REGI_COMP  TD_DT_001,
  @CSNU_ASTO	   TD_VC_010,
  @CSCO_UNID_CONC  TD_VC_003,
  @CSCO_TIPO_OPER  TD_VC_003,
  @VSNU_ASTO       TD_VC_008,
  @VDFE_REGI_COMP  TD_DT_001,
  @VSST_REGI_COMP  TD_VC_001,
  @VNNU_CORR_COMP  TD_IN_001,
  @VSNU_CORR_COMP  TD_VC_020,
  @VSST_FLAG       TD_VC_001,
  @VSCO_UNID_CONC  TD_VC_003,

  @VSCO_TIPO_OPER  TD_VC_003
*/


  Declare CT_TMDOCU_PROV_U01_1 Cursor
  For
  Select CO_EMPR, CO_PROV, CO_TIPO_DOCU, NU_DOCU_PROV, FE_PROG_PAGO, CO_USUA_MODI, FE_USUA_MODI
  From   Inserted

  Open  CT_TMDOCU_PROV_U01_1
  Fetch CT_TMDOCU_PROV_U01_1 
  Into @CSCO_EMPR, @CSCO_PROV, @CSCO_TIPO_DOCU, @CSNU_DOCU_PROV, @CDFE_PROG_PAGO, @CSCO_USUA_MODI, @CDFE_USUA_MODI
  
  While @@Fetch_Status = 0
  Begin
    If  @@Fetch_Status < 0
      Begin
        Close CT_TMDOCU_PROV_U01_1
        Deallocate CT_TMDOCU_PROV_U01_1
      End

	Select  @VNNU_CONT_PAGO = Count(FE_PROG)	     
	From TDPROG_PAGO
	Where CO_EMPR      = @CSCO_EMPR
	And   CO_PROV      = @CSCO_PROV
	And   CO_TIPO_DOCU = @CSCO_TIPO_DOCU
	And   NU_DOCU_PROV = @CSNU_DOCU_PROV
	If @VNNU_CONT_PAGO = 1
	   Update TDPROG_PAGO
	   Set	FE_PROG =  @CDFE_PROG_PAGO,
		CO_USUA_MODI  = @CSCO_USUA_MODI, 
		FE_USUA_MODI  = @CDFE_USUA_MODI
	   Where CO_EMPR      = @CSCO_EMPR
	   And   CO_PROV      = @CSCO_PROV
	   And   CO_TIPO_DOCU = @CSCO_TIPO_DOCU
	   And   NU_DOCU_PROV = @CSNU_DOCU_PROV



     Fetch CT_TMDOCU_PROV_U01_1 
     Into  @CSCO_EMPR, @CSCO_PROV, @CSCO_TIPO_DOCU, @CSNU_DOCU_PROV, @CDFE_PROG_PAGO, @CSCO_USUA_MODI, @CDFE_USUA_MODI

  End
  Close CT_TMDOCU_PROV_U01_1
  Deallocate CT_TMDOCU_PROV_U01_1
End
/*------------------------ Fin ----------------------*/
GO
ALTER TABLE [dbo].[TMDOCU_PROV] WITH NOCHECK ADD CONSTRAINT [CK__TMDOCU_PR__ST_AF__2DF1BF10] CHECK NOT FOR REPLICATION (([ST_AFEC_GAFI]='N' OR [ST_AFEC_GAFI]='S'))
GO
ALTER TABLE [dbo].[TMDOCU_PROV] WITH NOCHECK ADD CONSTRAINT [CK__TMDOCU_PR__ST_AF__2FDA0782] CHECK NOT FOR REPLICATION (([ST_AFEC_MORA]='N' OR [ST_AFEC_MORA]='S'))
GO
ALTER TABLE [dbo].[TMDOCU_PROV] WITH NOCHECK ADD CONSTRAINT [CK__TMDOCU_PR__ST_AF__31C24FF4] CHECK NOT FOR REPLICATION (([ST_AFEC_FLET]='N' OR [ST_AFEC_FLET]='S'))
GO
ALTER TABLE [dbo].[TMDOCU_PROV] WITH NOCHECK ADD CONSTRAINT [CK__TMDOCU_PR__ST_AF__5AC46587] CHECK NOT FOR REPLICATION (([ST_AFEC_IISC]='N' OR [ST_AFEC_IISC]='S'))
GO
ALTER TABLE [dbo].[TMDOCU_PROV] WITH NOCHECK ADD CONSTRAINT [CK__TMDOCU_PR__ST_AF__5E94F66B] CHECK NOT FOR REPLICATION (([ST_AFEC_RETE]='N' OR [ST_AFEC_RETE]='S'))
GO
ALTER TABLE [dbo].[TMDOCU_PROV] WITH NOCHECK ADD CONSTRAINT [CK__TMDOCU_PR__ST_CO__522F1F86] CHECK NOT FOR REPLICATION (([ST_CONT]='P' OR [ST_CONT]='N'))
GO
ALTER TABLE [dbo].[TMDOCU_PROV] WITH NOCHECK ADD CONSTRAINT [CK__TMDOCU_PR__ST_DC__33AA9866] CHECK NOT FOR REPLICATION (([ST_DCT1_BRAF]='N' OR [ST_DCT1_BRAF]='S'))
GO
ALTER TABLE [dbo].[TMDOCU_PROV] WITH NOCHECK ADD CONSTRAINT [CK__TMDOCU_PR__ST_DC__3592E0D8] CHECK NOT FOR REPLICATION (([ST_DCT1_BRIN]='N' OR [ST_DCT1_BRIN]='S'))
GO
ALTER TABLE [dbo].[TMDOCU_PROV] WITH NOCHECK ADD CONSTRAINT [CK__TMDOCU_PR__ST_DC__377B294A] CHECK NOT FOR REPLICATION (([ST_DCT1_GAFI]='N' OR [ST_DCT1_GAFI]='S'))
GO
ALTER TABLE [dbo].[TMDOCU_PROV] WITH NOCHECK ADD CONSTRAINT [CK__TMDOCU_PR__ST_DC__396371BC] CHECK NOT FOR REPLICATION (([ST_DCT1_MORA]='N' OR [ST_DCT1_MORA]='S'))
GO
ALTER TABLE [dbo].[TMDOCU_PROV] WITH NOCHECK ADD CONSTRAINT [CK__TMDOCU_PR__ST_DC__3B4BBA2E] CHECK NOT FOR REPLICATION (([ST_DCT1_FLET]='N' OR [ST_DCT1_FLET]='S'))
GO
ALTER TABLE [dbo].[TMDOCU_PROV] WITH NOCHECK ADD CONSTRAINT [CK__TMDOCU_PR__ST_DC__3D3402A0] CHECK NOT FOR REPLICATION (([ST_DCT2_BRAF]='N' OR [ST_DCT2_BRAF]='S'))
GO
ALTER TABLE [dbo].[TMDOCU_PROV] WITH NOCHECK ADD CONSTRAINT [CK__TMDOCU_PR__ST_DC__3F1C4B12] CHECK NOT FOR REPLICATION (([ST_DCT2_BRIN]='N' OR [ST_DCT2_BRIN]='S'))
GO
ALTER TABLE [dbo].[TMDOCU_PROV] WITH NOCHECK ADD CONSTRAINT [CK__TMDOCU_PR__ST_DC__41049384] CHECK NOT FOR REPLICATION (([ST_DCT2_GAFI]='N' OR [ST_DCT2_GAFI]='S'))
GO
ALTER TABLE [dbo].[TMDOCU_PROV] WITH NOCHECK ADD CONSTRAINT [CK__TMDOCU_PR__ST_DC__42ECDBF6] CHECK NOT FOR REPLICATION (([ST_DCT2_MORA]='N' OR [ST_DCT2_MORA]='S'))
GO
ALTER TABLE [dbo].[TMDOCU_PROV] WITH NOCHECK ADD CONSTRAINT [CK__TMDOCU_PR__ST_DC__44D52468] CHECK NOT FOR REPLICATION (([ST_DCT2_FLET]='N' OR [ST_DCT2_FLET]='S'))
GO
ALTER TABLE [dbo].[TMDOCU_PROV] WITH NOCHECK ADD CONSTRAINT [CK__TMDOCU_PR__ST_FL__672A3C6C] CHECK NOT FOR REPLICATION (([ST_FLET]='N' OR [ST_FLET]='S'))
GO
ALTER TABLE [dbo].[TMDOCU_PROV] WITH NOCHECK ADD CONSTRAINT [CK__TMDOCU_PR__ST_FO__607D3EDD] CHECK NOT FOR REPLICATION (([ST_FORM_1062]='N' OR [ST_FORM_1062]='S'))
GO
ALTER TABLE [dbo].[TMDOCU_PROV] WITH NOCHECK ADD CONSTRAINT [CK__TMDOCU_PR__ST_FO__6265874F] CHECK NOT FOR REPLICATION (([ST_FORM_1262]='N' OR [ST_FORM_1262]='S'))
GO
ALTER TABLE [dbo].[TMDOCU_PROV] WITH NOCHECK ADD CONSTRAINT [CK__TMDOCU_PR__ST_FO__644DCFC1] CHECK NOT FOR REPLICATION (([ST_FORM_1662]='N' OR [ST_FORM_1662]='S'))
GO
ALTER TABLE [dbo].[TMDOCU_PROV] WITH NOCHECK ADD CONSTRAINT [CK__TMDOCU_PR__ST_IG__6A06A917] CHECK NOT FOR REPLICATION (([ST_IGVP]='N' OR [ST_IGVP]='S'))
GO
ALTER TABLE [dbo].[TMDOCU_PROV] ADD CONSTRAINT [PK__TMDOCU_P__3D80D14749F9CC38] PRIMARY KEY CLUSTERED  ([CO_EMPR], [CO_PROV], [CO_TIPO_DOCU], [NU_DOCU_PROV]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[TMDOCU_PROV] ADD CONSTRAINT [FK__TMDOCU_PR__CO_CA__7D996BCF] FOREIGN KEY ([CO_CALI]) REFERENCES [dbo].[TTCALI_DOCP] ([CO_CALI])
GO
ALTER TABLE [dbo].[TMDOCU_PROV] ADD CONSTRAINT [FK__TMDOCU_PR__CO_EM__7E8D9008] FOREIGN KEY ([CO_EMPR]) REFERENCES [dbo].[TMPARA_TESO] ([CO_EMPR])
GO
ALTER TABLE [dbo].[TMDOCU_PROV] ADD CONSTRAINT [FK__TMDOCU_PR__CO_ES__7F81B441] FOREIGN KEY ([CO_ESTA_DOCU]) REFERENCES [dbo].[TTTIES_DOCU] ([CO_ESTA_DOCU])
GO
